<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Test2</title>
    <script src="https://cdn.jsdelivr.net/npm/vue@3.3.4/dist/vue.global.min.js"></script>
</head>
<body>
    <div id="app">
        <input v-model="firstName" placeholder="输入 first name">
        <input v-model="lastName" placeholder="输入 last name">
        <p>Full Name: {{ fullName }}</p>
    </div>

    <script>
        const { createApp, ref, watch, computed } = Vue;

        createApp({
            setup() {
                const firstName = ref('');
                const lastName = ref('');

                const fullName = computed(() => `${firstName.value} ${lastName.value}`);

                watch([firstName, lastName], ([newFirstName, newLastName], [oldFirstName, oldLastName]) => {
                    console.log(`First Name changed from "${oldFirstName}" to "${newFirstName}"`);
                    console.log(`Last Name changed from "${oldLastName}" to "${newLastName}"`);
                });

                return {
                    firstName,
                    lastName,
                    fullName,
                };
            }
        }).mount('#app');
    </script>
</body>
</html>
